package com.syswin.lhztest.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @auther: lhz
 * @data: 2019/1/18
 */
@EnableAsync(proxyTargetClass = true)
@Configuration
public class AsyncConfiguration {

   @Bean
   public AsyncTaskExecutor msgThreadPool() {
      ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
      executor.setThreadNamePrefix("async-msg-task");
      executor.setCorePoolSize(10);
      executor.setMaxPoolSize(20);
      executor.setQueueCapacity(20);
      executor.setKeepAliveSeconds(120);
      executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
      return executor;
   }
}
